package cn.gcjxsc.controller.member;

import cn.gcjxsc.data.query.salesman.IntegralRecordQuery;
import cn.gcjxsc.data.vo.salesman.statics.IntegralRecordSumVo;
import cn.gcjxsc.data.vo.salesman.statics.IntegralRecordVo;
import cn.gcjxsc.entity.salesman.IntegralRecord;
import cn.gcjxsc.service.integral.IntegralRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author pumbaa
 * @since 1.0
 */
@RestController("salesmanStaticsController")
@RequestMapping("/api/member")
public class StaticsController{
    @Autowired
    private IntegralRecordService integralRecordService;

    /**
     * 查询会员的创建的收益汇总,根据店铺分组
     *
     * @param refMemberId 业务员对应的会员id
     * @param memberId    被推荐的会员id
     * @return
     */
    @RequestMapping("/query/recMemberStoreStatics")
    public List<IntegralRecordSumVo> queryMemberStoreStatics(@RequestParam("refMemberId") Integer refMemberId,
                                                             @RequestParam("memberId") Integer memberId) {

        return integralRecordService.findMemberStoreStatics(refMemberId, memberId);
    }

    /**
     * 查询收益列表
     *
     * @param filter   过滤条件
     * @param page     当前页
     * @param pageSize 最大记录灵敏
     * @return
     */
    @RequestMapping("/query/recMemberStoreIncomeList")
    public List<IntegralRecordVo> queryMemberStoreIncomeList(IntegralRecordQuery filter,
                                                             @RequestParam(value = "page", defaultValue = "1", required = false) int page,
                                                             @RequestParam(value = "pageSize", defaultValue = "30", required = false) int pageSize) {
        page = Math.abs(page == 0 ? 1 : page);
        Page<IntegralRecord> pageList = integralRecordService.findList(filter, page, pageSize);
        return integralRecordService.convertList(pageList.getContent());
    }
}
